/**
 * @file BluetoothTransparentModInitializer.h
 * @author your name (you@domain.com)
 * @brief 
 * @version 0.1
 * @date 2023-06-27
 * 
 * @copyright Copyright (c) 2005-2023 XAG Co., Ltd. All Rights Reserved
 * 
 */

#include "BluetoothTransparentModInitializer.h"
#include <memory>
#include "XagLog.h"
#include "BluetoothTransparentModule.h"

using business_modules_xnetcomm::XnetCommModule;

namespace business_modules_bluetoothtransparent {

bool BluetoothTransparentModInitializer::InitModule(
                kapok_module_management::ModuleResource *pobjModResource,
                std::shared_ptr<kapok_module_management::BaseModule> pobjModule)  {
    if (NULL == pobjModResource || nullptr == pobjModule) {
        XAG_LOG_E("cloudlog init failed, input pointer null");
        return false;
    }

    std::shared_ptr<BluetoothTransparentModule> pobjBluetoothTransparentModuleule =
                    std::dynamic_pointer_cast<BluetoothTransparentModule>(pobjModule);
    if (nullptr == pobjBluetoothTransparentModuleule) {
        XAG_LOG_E("module %s init failed, cast error", pobjModule->GetModuleName().c_str());
        XAG_LOGF_I("BluetoothTransparentModule typeid: {}", typeid(BluetoothTransparentModule).name());
        XAG_LOGF_I("*pobjModule typeid: {}", typeid(*pobjModule).name());
        return false;
    }

    std::shared_ptr<XnetCommModule> pXetComm =
                        pobjModResource->GetModule<XnetCommModule>(MODULE_NAME_XNET_COMM);
    if (nullptr != pXetComm) {
        pobjBluetoothTransparentModuleule->SetXnetCommModule(pXetComm);
    } else {
        XAG_LOGF_E("*xnet comm module get failed");
    }


    pobjBluetoothTransparentModuleule->Init();
    XAG_LOG_I("module %s inited", pobjBluetoothTransparentModuleule->GetModuleName().c_str());

    return true;
}

bool BluetoothTransparentModInitializer::UninitModule(
                        kapok_module_management::ModuleResource *pobjModResource,
                        std::shared_ptr<kapok_module_management::BaseModule> pobjModule) {
    if (NULL == pobjModResource || nullptr == pobjModule) {
        return false;
    }

    std::shared_ptr<BluetoothTransparentModule> pobjBluetoothTransparentModuleule =
                    std::dynamic_pointer_cast<BluetoothTransparentModule>(pobjModule);
    if (nullptr != pobjBluetoothTransparentModuleule) {
        XAG_LOG_I("module %s uninited", pobjBluetoothTransparentModuleule->GetModuleName().c_str());
        pobjBluetoothTransparentModuleule->Uninit();
        return true;
    } else {
        XAG_LOG_E("module uninit failed, cast error");
        XAG_LOGF_I("BluetoothTransparentModule typeid: {}", typeid(BluetoothTransparentModule).name());
        XAG_LOGF_I("*pobjModule typeid: {}", typeid(*pobjModule).name());
        return false;
    }
}

} /* namespace business_modules_bluetoothtransparent */
